#pragma once

#include <QtWidgets/QMainWindow>
#include <QButtonGroup>
#include <QFile>
#include <QFileDialog>
#include <QCryptographicHash>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QJsonParseError>
#include <QJsonObject>
#include <QDateTime>
#include "log.h"
#include "const.h"
#include <curl/curl.h>
#include "httpcommon.h"
#include "ui_upload.h"
#include "uploaditem.h"
#include "globaldata.h"

class Upload : public QWidget
{
    Q_OBJECT

public:
	Upload(QWidget *parent = Q_NULLPTR);
	~Upload();
	void uploadFile(QString dirID);
	private Q_SLOTS:
	void finishUploadSlot(QString itemID, QString filename, QString fileBasename, int filesize, QString dirID);
	void pauseUploadSlot(QString itemID);
	void resumeUploadSlot(QString itemID);
	void deleteUploadSlot(QString itemID);
	void updateProgressValueSlot(QString itemID, int progress);
	public Q_SLOTS:
	void on_pbStartAll_clicked();
	void on_pbPauseAll_clicked();
	void on_pbCancelAll_clicked();
Q_SIGNALS:
	void refreshResourceListSignal();
	void refreshFinishSignal();
	void showMessageSignal(QString, int);
private:
	void loadUploadData();
	QString getItemID();
	QString notifyFileServer(QString filename);
	void addUploadItem(QString itemID, QString filePath, QString status, int progress, QString dirID);
	void notifyPlatform(QString recordID, QString fileBasename, int filesize, QString dirID);
private:
    Ui::Upload ui;
	QString m_uploadUrl;
	QMap<QString, UploadItem*> m_uploadMap;
};
